/**
 * Author(s): xuming.Wong <xuming.Wong@gmail.com>
 */

#ifndef __GPK_H__
#define __GPK_H__

#include "EnginePrerequisites.h"

#define GPACK_FILE_LIMIT 4096//a .gpk can only contain less than 4096 file,i think it sufficient
#define GPACK_FILE_COPY_BUF 4194304//4M

namespace PQEngine
{

	//file names are stored in .gpkname
	struct GPKFileInfo
	{
		int offset;//file data offset abs from .gpk start
		int size;//file size in bytes
		/*
		0:No file data
		1:Used
		2:File data removed but data not corrupted,can recover file
		when remove a file just set state=2,
		*/
		int state;//state=0;No file data state=1
		int id;//auto generate now just index of the GPKFileInfo list
		int type;//see GFileType
		
		//may use md5 for id?Or filename hash value?now do nothing for simplicity
		//add new field above this line,and minus unused array size by 1(next line).
		int unused[5];//will sufficient for futher use,such as how file compressed
	};

	//Note:It's better to use small archives than single large archive with .gpk.
	struct GPKHeader
	{
	public:

		char magic[4];//Always ".gpk"
		int version;//now 1
		
		//file system hierachy may implement in .gpkassist
		int numFile;//number of files in this .gpk archive

		int unused[16];//will sufficient for futher use
		
		//maximum 1024 file per archive
		GPKFileInfo infos[GPACK_FILE_LIMIT];//GPKFileInfo start byte offset(relative to the start of .gpk archive file)
		

	public:
		GPKHeader()
		{
			magic[0]='.';
			magic[1]='g';
			magic[2]='p';
			magic[3]='k';
			version=1;
			numFile=0;
			memset(unused,0,sizeof(int)*16);
			memset(infos,0,sizeof(GPKFileInfo)*GPACK_FILE_LIMIT);
		}
		
	};
	
}
#endif


